# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: mio <miyopan@e.email>
pkgname=xournalpp
pkgver=1.2.4
pkgrel=0
pkgdesc="Xournal++ is a handwriting notetaking software with PDF annotation support"
url="https://github.com/xournalpp/xournalpp"
# loongarch64: blocked by qt5-qtwebengine
arch="all !loongarch64"
license="GPL-2.0-or-later"
depends="adwaita-icon-theme"
makedepends="
	cmake
	glib-dev
	gtest-dev
	gtk+3.0-dev
	gtksourceview4-dev
	help2man
	librsvg-dev
	libsndfile-dev
	libx11-dev
	libxi-dev
	libxml2-dev
	libzip-dev
	lsb-release
	lua5.4-dev
	poppler-dev
	portaudio-dev
	samurai
	"
options="!check" # 2 failed unit tests
subpackages="$pkgname-dbg $pkgname-doc $pkgname-lang"
source="xournalpp-$pkgver.tar.gz::https://github.com/xournalpp/xournalpp/archive/v$pkgver.tar.gz
	no-execinfo.patch
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi

	# Increase stack-size to avoid crashes when using pen for input
	LDFLAGS="$LDFLAGS -Wl,-z,stack-size=2097152" \
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DLUA_LIBRARIES="/usr/lib/lua5.4/liblua.so" \
		-DENABLE_GTEST=on \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		$CMAKE_CROSSOPTS
	cmake --build build --target all translations
}

check() {
	cmake --build build --target test-units
	cmake --build build --target test
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	install -Dm0644 LICENSE "$pkgdir"/usr/share/licenses/xournalpp/LICENSE
}

sha512sums="
45f09757f8dba67f64d53cd05c400bd563e5168eb24d1a0b5a4c407427dc4427adf54d22c5cae6a56945cef71016ff23cad077994dcb20f262082380dd284094  xournalpp-1.2.4.tar.gz
1046141c3b51286fee439b4bba1ea247e7d121054b64134eecfb5859932d55d5afbf617052502bd7ca110928122b9690d463d579ed1575cf37b52ce318b087ca  no-execinfo.patch
"
